Public Class frmRenameComputers

    Private Sub btnRenameComputersCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRenameComputersCancel.Click
        Me.Close()
    End Sub

    Private Sub btnRenameComputersOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRenameComputersOK.Click
        Dim name As String = ""
        Dim i As Integer
        Dim currentNumber As Integer
        Dim currentNumberStr As String
        Dim allNames As String = ""

        currentNumber = numRenameComputersStart.Value
        For i = 0 To frmMain.gridComputers.SelectedRows.Count - 1
            If allNames = "" Then
                allNames = frmMain.gridComputers.SelectedRows(i).Tag 'Cells(0).Value
            Else
                allNames = allNames & "::" & frmMain.gridComputers.SelectedRows(i).Tag 'Cells(0).Value
            End If
            name = txtRenameComputersName.Text.Replace("$i", "$I").Replace("$m1", "$M1").Replace("$m2", "$M2")
            name = name.Replace("$u", "$U").Replace("$n", "$N").Replace("$s", "$S")
            name = name.Replace("$I", frmMain.gridComputers.SelectedRows(i).Cells(1).Value.ToString.Replace(".", "_"))
            name = name.Replace("$M1", Split(frmMain.gridComputers.SelectedRows(i).Cells(5).Value, " ")(0))
            name = name.Replace("$M2", Split(frmMain.gridComputers.SelectedRows(i).Cells(5).Value, " ")(1))
            name = name.Replace("$S", frmMain.gridComputers.SelectedRows(i).Cells(10).Value())
            name = name.Replace("$U", Split(frmMain.gridComputers.SelectedRows(i).Cells(9).Value, "\")(1))

            currentNumberStr = currentNumber.ToString
            While numRenameComputersPadding.Value > currentNumberStr.Length
                currentNumberStr = "0" & currentNumberStr
            End While
            name = name.Replace("$N", currentNumberStr)
            currentNumber = currentNumber + numRenameComputersIncrease.Value
            name = name.Replace(":", "")
            allNames = allNames & ":" & name
        Next

        'NOTE
        'since we run this locally, do we assume they can change computer names?
        'the answer is yes
        'if not, then uncomment and tweak the code below
        '
        'If options.security.domainAdminUser = "" Then
        'allNames = InputBox("Please enter the username of a member of the Domain Admins group:", "Domain Admin Username") & ":" & InputBox("Please enter the password for that user:", "Domain Admin Password") & "::" & allNames
        'Else
        'allNames = options.security.domainAdminUser & ":" & options.security.domainAdminPassword & "::" & allNames
        'End If
        If MsgBox("You are about to rename all of the selected computers to look similar to this: " & name & ControlChars.CrLf & ControlChars.CrLf & "Are you sure you want to rename the selected computers?", MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2) = MsgBoxResult.Yes Then
            frmMain.net.adminRenameComputers(allNames)
            MsgBox("Selected computers will be renamed when they check in next.", MsgBoxStyle.Information)
            Me.Close()
        End If
    End Sub
End Class